//
//  PerWalletViewController.m
//  CYWFrame
//
//  Created by Macx on 2017/9/22.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "PerWalletViewController.h"
#import "PerWalletTableViewCell.h"
#import "WalletHeaderCell.h"
#import "PerWalletRecordViewController.h"

#import "AliPayServer.h"
#import <AlipaySDK/AlipaySDK.h>

@interface PerWalletViewController () <UITableViewDelegate, UITableViewDataSource>


@property (nonatomic, strong) NSMutableArray *liveRateArr;

@property (nonatomic, strong) NSDictionary *MoneyratesDict;

@property (nonatomic, strong) NSString *accountM; // 账户余额

@property (nonatomic, strong) NSMutableArray *accountRateArr;

@property (nonatomic, strong) NSString *amount; // 选择充值的金额

@property (nonatomic, strong) NSMutableArray *btnArr;

@end

@implementation PerWalletViewController {
    UITableView *_tableView1;
    UIScrollView    *_scrollView;

    UILabel     *_accountMoney;
    UILabel     *_withdrawal;
    UIButton    *_withdrawalBtn;
    UILabel     *_liveMoney;
    UIImageView *_chooseImg1;
    UIImageView *_chooseImg2;
    
    CGSize  _size1;
    CGSize  _size2;
    CGSize  _size3;
}

- (void)viewWillAppear:(BOOL)animated {
    [self updateUserInfo];
}

// 主页tableView是否滚动接收到通知
- (void)notificationPay:(NSNotification *)notification {
    NSLog(@"－－－－－钱包收到微信支付接收到通知------");
    [self updateUserInfo];
}

//移除广播监听。
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationPay:) name:@"payWallet" object:nil];
    
    self.amount = @"";
    
    self.view.backgroundColor = kWhiteColor;
    
    [self GETMoneyrates];
    
//    [self buildUI];
    
}


#pragma mark ==========构建UI==========
- (void)buildUI {
    
    self.navigationItem.title = @"秀币充值";
    
    self.automaticallyAdjustsScrollViewInsets = NO;
	
	/*
    UIButton * right = [UIButton buttonWithType:UIButtonTypeCustom];
    [right setTitle:@"支出记录" forState:UIControlStateNormal];
    right.titleLabel.font = kUHSystemFontWithSize(14);
    right.frame = CGRectMake(0, 0, [LZCTools textSizeWithText:right.titleLabel.text font:right.titleLabel.font].width, 44);
    right.titleLabel.textAlignment = NSTextAlignmentRight;
    [right setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [right addTarget:self action:@selector(recordMoney:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:right];
	 */
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    [self.view addSubview:_scrollView];
    
    _size1 = [LZCTools textSizeWithText:@"秀币余额" font:kUHSystemFontWithSize(15)];
    _size2 = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(16)];
    _size3 = [LZCTools textSizeWithText:@"请选择支付金额" font:kUHSystemFontWithSize(13)];
	
	
	
    NSArray *arr = @[@"    账户余额（元）", @"    可提现金额（元）"];
    
    CGFloat y = 10.0;
	/*
    for (int i = 0; i < arr.count; i++) {
        UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, y, SW(2), _size1.height)];
        [_scrollView addSubview:l];
        l.font = kUHSystemFontWithSize(15);
        l.textColor = kGrayColor;
//        l.text = arr[i];
        
        if (i == 1) {
            
//            _accountMoney = l;
//            l.textColor = UIMainColorRGB;
//        }
//        else {
            _withdrawal = l;
            l.textColor = kOrangeColor;
        }
        else {
            l.text = arr[i];
        }
        y = 2*y+_size1.height;
    }
//    for (int i = 0; i < arr.count; i++) {
//        for (int j = 0; j < arr.count; j++) {
//            UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(SW(2)*j, y, SW(2), _size1.height)];
//            [_scrollView addSubview:l];
//            l.font = kUHSystemFontWithSize(15);
//            l.textColor = kGrayColor;
//            l.text = arr[i];
//    
//            if (i == 1) {
//                if (j==0) {
//                    _accountMoney = l;
//                    l.textColor = UIMainColorRGB;
//                }
//                else {
//                    _withdrawal = l;
//                    l.textColor = kOrangeColor;
//                }
//            }
//        }
//        y = 2*y+_size1.height;
//    }

	
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(SW(2), 5, 1, 25+_size1.height*2)];
    [_scrollView addSubview:line];
    line.backgroundColor = UISeparatedColorRGB;
    line.hidden = YES;
    
    
    _withdrawalBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_scrollView addSubview:_withdrawalBtn];
    [_withdrawalBtn setTitle:@"去提现" forState:UIControlStateNormal];
    [_withdrawalBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [_withdrawalBtn addTarget:self action:@selector(withdrawalClick:) forControlEvents:UIControlEventTouchUpInside];
    _withdrawalBtn.titleLabel.font = kUHSystemFontWithSize(15);
    _withdrawalBtn.frame = CGRectMake(SCREEN_WIDTH-20-_size1.width, line.y+line.height, _size1.width+10, _size1.height+10);
    _withdrawalBtn.layer.cornerRadius = _withdrawalBtn.height/2;
    [_withdrawalBtn setBackgroundColor:UIMainColorRGB];
    _withdrawalBtn.layer.masksToBounds = YES;
    
    
    UIButton *allMoneyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_scrollView addSubview:allMoneyBtn];
    [allMoneyBtn setTitle:@"收支明细" forState:UIControlStateNormal];
    [allMoneyBtn setTitleColor:UIMainColorRGB forState:UIControlStateNormal];
    allMoneyBtn.titleLabel.font = kUHSystemFontWithSize(15);
    allMoneyBtn.frame = CGRectMake(_withdrawalBtn.x, 10, _withdrawalBtn.width, _withdrawalBtn.height);
    [allMoneyBtn addTarget:self action:@selector(paymentDetailsClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(0, _withdrawalBtn.height+_withdrawalBtn.y+10, SCREEN_WIDTH, 10)];
	 */
	
	UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
    [_scrollView addSubview:line2];
    line2.backgroundColor = UISeparatedColorRGB;
    
    y = line2.y+line2.height+10;
    for (int i = 0; i < 2; i++) {
        UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, y, SCREEN_WIDTH, _size1.height)];
        [_scrollView addSubview:l];
        l.text = @"    秀币余额";
        l.font = kUHSystemFontWithSize(15);
        l.textColor = kGrayColor;
        if (i == 1) {
            l.textColor = UIMainColorRGB;
            _liveMoney = l;
        }
        y = y+10+_size1.height;
    }
    
    // 赋值
    _accountMoney.text = [NSString stringWithFormat:@"    %.2lf", self.coin];
    _withdrawal.text = [NSString stringWithFormat:@"    %.2lf", self.withdrawable_money];
    _liveMoney.text = [NSString stringWithFormat:@"    %.2lf", self.money];
    
    
    UIView *line3 = [[UIView alloc] initWithFrame:CGRectMake(0, y, SCREEN_WIDTH, 10)];
    [_scrollView addSubview:line3];
    line3.backgroundColor = UISeparatedColorRGB;
    
    NSArray *wayArr = @[@"余额充值", @"秀币充值"];
    CGFloat Y = line3.y+10;
    for (int i = 0; i < wayArr.count; i++) {
        UIButton *wayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_scrollView addSubview:wayBtn];
        [wayBtn setTitle:[NSString stringWithFormat:@"%@", wayArr[i]] forState:UIControlStateNormal];
        wayBtn.titleLabel.font = kUHSystemFontWithSize(15);
        CGSize bsize = [LZCTools textSizeWithText:wayBtn.titleLabel.text font:kUHSystemFontWithSize(15)];
        wayBtn.frame = CGRectMake(0, Y, bsize.width+10, 30);
        wayBtn.centerX = SW(2)*i + SW(4);
        [wayBtn setTitleColor:kGrayColor forState:UIControlStateNormal];
        [wayBtn setTitleColor:UIMainColorRGB forState:UIControlStateSelected];
        [wayBtn addTarget:self action:@selector(wayAction:) forControlEvents:UIControlEventTouchUpInside];
        wayBtn.tag = 31+i;
        
        CGFloat lineY = wayBtn.y+wayBtn.height;
        
        UIView *pinkV = [[UIView alloc] initWithFrame:CGRectMake(wayBtn.x, lineY, wayBtn.width, 2)];
        [_scrollView addSubview:pinkV];
        pinkV.backgroundColor = kClearColor;
        pinkV.tag = 41+i;
        if (i==1) {
            wayBtn.selected = YES;
            pinkV.backgroundColor = UIMainColorRGB;
            wayBtn.centerX = SW(2);
            pinkV.centerX = wayBtn.centerX;
        }
        else {
            wayBtn.hidden = YES;
            pinkV.hidden = YES;
        }
        
    }

    UIView *line4 = [[UIView alloc] initWithFrame:CGRectMake(0, Y+35, SCREEN_WIDTH, 1)];
    [_scrollView addSubview:line4];
    line4.backgroundColor = UISeparatedColorRGB;
    
//    NSArray *arr3 = self.MoneyratesDict[@"coin_denominations"];
    NSMutableArray *arr3 = [NSMutableArray arrayWithArray:self.MoneyratesDict[@"coin_denominations"]];
    [arr3 addObject:@"其他金额"];
    CGFloat btnW = (SCREEN_WIDTH-40)/3;
    CGFloat btnH = 30;
    for (int i = 0; i < arr3.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_scrollView addSubview:btn];
        btn.frame = CGRectMake(10+(btnW+10)*(i%3), line4.y+11+40*(i/3), btnW, btnH);
//        btn.layer.cornerRadius = 5;
//        btn.layer.borderWidth = 1;
//        btn.layer.borderColor = kGrayColor.CGColor;
        [btn setBackgroundImage:IMAGE(@"icon_border_green") forState:UIControlStateSelected];
        [btn setBackgroundImage:IMAGE(@"-icon_border") forState:UIControlStateNormal];
        [btn setTitleColor:kGrayColor forState:UIControlStateNormal];
        [btn setTitleColor:UIMainColorRGB forState:UIControlStateSelected];
        btn.titleLabel.font = kUHSystemFontWithSize(15);
        [btn setTitle:arr3[i] forState:UIControlStateNormal];
        if (i != arr3.count-1) {
            [btn setTitle:[NSString stringWithFormat:@"%@ 元", arr3[i]] forState:UIControlStateNormal];
        }
        [btn addTarget:self action:@selector(rateClick:) forControlEvents:UIControlEventTouchUpInside
         ];
        
        btn.tag = 100+i;
        [self.accountRateArr addObject:btn];
        btn.hidden = YES;
    }
    
    _chooseImg1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    [_scrollView addSubview:_chooseImg1];
    _chooseImg1.image = IMAGE(@"charge_shose");
    _chooseImg1.hidden = YES;
    
    _chooseImg2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    [_scrollView addSubview:_chooseImg2];
    _chooseImg2.image = IMAGE(@"charge_shose");
    _chooseImg2.hidden = YES;
    
    y = line4.y+11+40*(arr3.count/3);
//    UIView *line5 = [[UIView alloc] initWithFrame:CGRectMake(0, y, SCREEN_WIDTH, 10)];
//    [_scrollView addSubview:line5];
//    line5.backgroundColor = UISeparatedColorRGB;
    
    
    
    
//    _tableView1 = [[UITableView alloc] initWithFrame:CGRectMake(0, line4.y+1, SCREEN_WIDTH, SCREEN_HEIGHT-(line4.y+11)) style:UITableViewStyleGrouped];
    _tableView1 = [[UITableView alloc] initWithFrame:CGRectMake(0, line4.y+1, SCREEN_WIDTH, SW(8)*6) style:UITableViewStylePlain];
    [_scrollView addSubview:_tableView1];
    _tableView1.scrollEnabled = NO;
    _tableView1.delegate = self;
    _tableView1.dataSource = self;
    _tableView1.tableFooterView = [[UIView alloc]init];
    _tableView1.tableHeaderView.userInteractionEnabled = YES;
//    _tableView1.hidden = YES;
    
    [_tableView1 registerNib:[UINib nibWithNibName:@"PerWalletTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    
    UIView *footerView = [self createFooterView:CGRectMake(0, _tableView1.y+_tableView1.height+10, SCREEN_WIDTH, 81+_size1.height)];
    [_scrollView addSubview:footerView];
    
    _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, footerView.y+footerView.height);
    
}

- (UIView *)createFooterView:(CGRect)frame {
    UIView *view = [[UIView alloc] initWithFrame:frame];
    
    UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, _size1.height)];
    [view addSubview:l];
    l.text = @"   充值方式";
    l.font = kUHSystemFontWithSize(15);
    l.textColor = kGrayColor;
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, l.y+l.height+10, SCREEN_WIDTH, 1)];
    [view addSubview:line];
    line.backgroundColor = UISeparatedColorRGB;
    
    NSArray *imgArr = @[@"pay_wechat2", @"pay_alipay2"];
    NSArray *colorArr = @[RGB(33, 184, 81), RGB(38, 179, 239)];
    NSArray *textArr = @[@" 微信充值", @" 支付宝充值"];
    CGFloat btnW = (SCREEN_WIDTH-30)/2;
    CGFloat btnH = 40;
    for (int i = 0; i < imgArr.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [view addSubview:btn];
        btn.frame = CGRectMake(10+(btnW+10)*i, line.y+11, btnW, btnH);
//        [btn setBackgroundImage:IMAGE(imgArr[i]) forState:UIControlStateNormal];
        [btn setBackgroundColor:colorArr[i]];
        [btn setImage:IMAGE(imgArr[i]) forState:UIControlStateNormal];
        [btn setTitle:textArr[i] forState:UIControlStateNormal];
        btn.titleLabel.font = kUHSystemFontWithSize(12);
        [btn addTarget:self action:@selector(chargClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 500+i;
//        if (i == 0) {
//            btn.hidden = YES;
//        }
    }
    
    return view;
}

- (void)rateClick:(UIButton *)btn {
    
    self.accountM = btn.titleLabel.text;
    NSLog(@"点击余额充值 = %@ %ld", self.accountM, btn.tag);
    
    
    _chooseImg1.x = btn.x+btn.width-20;
    _chooseImg1.y = btn.y+btn.height-20;
    _chooseImg1.hidden = NO;

    
    NSInteger tag = btn.tag;
    btn.selected = YES;
    
    for (int i = 0; i < self.accountRateArr.count; i++) {
        UIButton *button = self.accountRateArr[i];
        if (button.tag != tag) {
            button.selected = NO;
        }
    }
    
}

- (void)wayAction:(UIButton *)sender {
    UIView *line1 = [self.view viewWithTag:41];
    UIView *line2 = [self.view viewWithTag:42];
    UIButton *btn1 = [self.view viewWithTag:31];
    UIButton *btn2 = [self.view viewWithTag:32];
    if (sender.tag == 31) {
        line1.backgroundColor = UIMainColorRGB;
        line2.backgroundColor = kClearColor;
        btn1.selected = YES;
        btn2.selected = NO;
        _tableView1.hidden = YES;
        _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-64);
    }
    else {
        line2.backgroundColor = UIMainColorRGB;
        line1.backgroundColor = kClearColor;
        btn1.selected = NO;
        btn2.selected = YES;
        _tableView1.hidden = NO;
        _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, _tableView1.y+_tableView1.height);
    }

}

- (void)chargClick:(UIButton *)sender {
    
    if ([self.amount isEqualToString:@""]) {
        [self presentViewController:[LZCTools alertMessage:@"请选择充值金额"] animated:YES completion:nil];
        return;
    }
    NSString *channel;
    if (sender.tag == 500) {
        channel = @"wx_app";
    }
    else
        channel = @"ali_app";
    
    NSDictionary *param = @{@"type":@"charge",
                            @"channel":channel,
                            @"amount":[NSString stringWithFormat:@"%ld", [self.amount integerValue]*100]};
    
    [[NetworkTool sharedTool] requestWithName:@"发起秀币充值" URLString:APIPaymentCharge parameters:param method:@"POST" callBack:^(id responseObject) {
//        [AliPayServer aliPay:responseObject[@"data"][@"param_str"]];
        if ([channel isEqualToString:@"wx_app"]) {
            [AliPayServer wxPay:responseObject[@"data"][@"param_obj"]];
        }
        else if ([channel isEqualToString:@"ali_app"]) {
            
            [AliPayServer aliPay:responseObject[@"data"][@"param_str"] memo:@"充值成功"];
            
            // NOTE: 调用支付结果开始支付
//            [[AlipaySDK defaultService] payOrder:responseObject[@"data"][@"param_str"] fromScheme:@"alipaycywkj" callback:^(NSDictionary *resultDic) {
//                NSLog(@"支付===reslut = %@",resultDic);
                
//                if ([resultDic[@"memo"] isEqualToString:@""]) {
//                    [self updateUserInfo];
//                    [self presentViewController:[LZCTools alertMessage:@"充值成功"] animated:YES completion:nil];
//                }
//                else
//                    [self presentViewController:[LZCTools alertMessage:resultDic[@"memo"]] animated:YES completion:nil];
                
//            }];
        }

        
    }];
    
}

#pragma mark ==========UITableView==========
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    PerWalletTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.money.text = self.liveRateArr[indexPath.row][0];
    [cell.moneyBtn setTitle:self.liveRateArr[indexPath.row][1] forState:UIControlStateNormal];
    
    
    [cell.moneyBtn setBackgroundImage:IMAGE(@"-icon_border") forState:UIControlStateNormal];
    [cell.moneyBtn setBackgroundImage:IMAGE(@"icon_border_green") forState:UIControlStateSelected];

    cell.moneyBtn.tag = indexPath.row;
    [cell.moneyBtn addTarget:self action:@selector(moneySelectClick:) forControlEvents:UIControlEventTouchUpInside];
    
//    [mArray replaceObjectAtIndex:0 withObject:@“小子”]
    [self.btnArr replaceObjectAtIndex:indexPath.row withObject:cell.moneyBtn];
    
//    [cell.moneyBtn setBackgroundImage:IMAGE(@"placeHolder") forState:UIControlStateSelected];
    
    return cell;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.liveRateArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return SW(8);
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSLog(@"点击tableView.cell = %ld", indexPath.row);
    
//    PerWalletTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
//    
//    if (cell.moneyBtn.isSelected == NO) {
//        self.amount = self.liveRateArr[indexPath.row][1];
//        cell.moneyBtn.selected = YES;
//    }
//    else {
//        
//        self.amount = @"";
//        cell.moneyBtn.selected = NO;
//    }
    
//    -icon_border
//    icon_border_green
    
//    if
    
    
    
}

#pragma mark ==========响应方法==========
- (void)recordMoney:(id)sender {
    NSLog(@"点击充值记录");
    PerWalletRecordViewController *recordVC = [[PerWalletRecordViewController alloc] init];
    recordVC.type = 4;
    [self.navigationController pushViewController:recordVC animated:YES];
}
- (void)withdrawalClick:(UIButton *)sender {
    NSLog(@"点击提现");
    PerWalletRecordViewController *recordVC = [[PerWalletRecordViewController alloc] init];
    recordVC.type = 2;
    recordVC.largestAmount = [NSString stringWithFormat:@"%.2lf", self.withdrawable_money];
    [self.navigationController pushViewController:recordVC animated:YES];
}

- (void)paymentDetailsClick:(UIButton *)sender {
    PerWalletRecordViewController *recordVC = [[PerWalletRecordViewController alloc] init];
    recordVC.type = 1;
    [self.navigationController pushViewController:recordVC animated:YES];
}

- (void)GETMoneyrates {
    [[NetworkTool sharedTool] requestWithName:@"获取虚拟币比率" URLString:APIMoneyrates parameters:nil method:@"GET" callBack:^(id responseObject) {
        
        self.MoneyratesDict = responseObject[@"data"];
        
        for (NSString *str in self.MoneyratesDict[@"money_denominations"]) {
            NSMutableArray *mA = [[NSMutableArray alloc] init];
			NSString *str1 = [NSString stringWithFormat:@"%@", str];
            [mA addObject:str1];
			NSString *str2 = [NSString stringWithFormat:@"%.2lf 元", [str integerValue]*[self.MoneyratesDict[@"money_rate"] doubleValue]];
            [mA addObject:str2];
            [self.liveRateArr addObject:mA];
            
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [self.btnArr addObject:btn];
            
        }
        
        [self buildUI];
    }];
}


/**
 更新用户信息
 */
- (void)updateUserInfo {
    
    [[NetworkTool sharedTool] requestWithName:@"获取用户信息" URLString:APIUser parameters:nil method:@"GET" callBack:^(id responseObject) {
        NSDictionary *userDict = [responseObject valueForKey:@"data"];
        
        _accountMoney.text = [NSString stringWithFormat:@"    %.2f", [[userDict valueForKey:@"coin"] floatValue]/100];
        _withdrawal.text = [NSString stringWithFormat:@"    %.2f", [[userDict valueForKey:@"withdrawable_money"] floatValue]/100];
//        _liveMoney.text = [NSString stringWithFormat:@"    %.2f", [[userDict valueForKey:@"money"] floatValue]/100];
        _liveMoney.text = [NSString stringWithFormat:@"    %@", [userDict valueForKey:@"coin"]];
        
        self.coin = [_accountMoney.text floatValue];
        self.withdrawable_money = [_withdrawal.text floatValue];
        self.money = [_liveMoney.text floatValue];
        
        //创建通知
        NSNotification *notification =[NSNotification notificationWithName:@"liveMoney" object:nil userInfo:@{@"xiubi":_liveMoney.text}];
        //通过通知中心发送通知
        [[NSNotificationCenter defaultCenter] postNotification:notification];
        
    }];
}

- (void)moneySelectClick:(UIButton *)btn {
    
    for (UIButton *b in self.btnArr) {
        b.selected = NO;
        self.amount = @"";
    }
    
    if (btn.isSelected == NO) {
        self.amount = self.liveRateArr[btn.tag][1];
        btn.selected = YES;
    }
    else {
        self.amount = @"";
        btn.selected = NO;
    }
    
}

// 懒加载
- (NSMutableArray *)accountRateArr {
    if (_accountRateArr == nil) {
        _accountRateArr = [[NSMutableArray alloc] init];
    }
    return _accountRateArr;
}

- (NSMutableArray *)liveRateArr {
    if (_liveRateArr == nil) {
        _liveRateArr = [[NSMutableArray alloc] init];
    }
    return _liveRateArr;
}

- (NSMutableArray *)btnArr {
    if (_btnArr == nil) {
        _btnArr = [[NSMutableArray alloc] init];
    }
    return _btnArr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
